<template>
    <div class="waiting-queue-box">
        <div class="waiting-content-v">
            <commpVxeTable
            :key="refreshTable"
            :isCanWrap="true"
            :config="dataTableConfig" 
            :columns="columnsVxe" 
            :formItem="formItem"
            ref="acceptanceRegistrationRef"
            @checkboxChange="checkboxChange"
            >
                <template v-slot:externalOperations="{data}">
                    <vxe-form-item>
                        <template>
                            <a-button class="blue-btn" type="primary" @click="printAllTableClick({isPrintAll:'是'})">打印全部记录表</a-button>
                        </template>
                    </vxe-form-item>
                    <vxe-form-item>
                        <template>
                            <a-button class="blue-btn" type="primary" @click="printAllTableClick()">打印记录表</a-button>
                        </template>
                    </vxe-form-item>
                    <vxe-form-item>
                        <template>
                            <a-button class="blue-btn" type="primary" @click="printBatchDetailsClick(0)">批量打印详情</a-button>
                        </template>
                    </vxe-form-item>
                </template>
                <template v-slot:fhyzt_name="{row}">
                    <span style="color: #ee6666;" v-if="row.fhyzt == '未开始'">未开始</span>
                    <span style="color: #91cc75;" v-if="row.fhyzt == '已完成'">已完成</span>
                </template>
                <template v-slot:operation_btn="{row}">
                    <a-form layout="inline" class="search-form" >
                        <a-form-item >
                            <a-button class="blue-btn" type="primary" @click="handleClick(row,0,true)">查看</a-button>
                        </a-form-item>
                        <a-form-item >
                            <a-button class="blue-btn" type="primary" @click="printDetailsClick(row)">打印详情</a-button>
                        </a-form-item>
                    </a-form>
                </template>
            </commpVxeTable>
            <handleaddEdit ref="addEditRef0" @addItem="addItem" @editItem="editItem" />
            <recordPrint ref="recordPrintRef" />
            <recordPrintTable ref="recordPrintTableRef" />
        </div>
    </div>
</template>
<script>
import assessCheckApi from './service/api'
import commpVxeTable from '@/components/commp-vxe-table/commp-vxe-table.vue'
import blobType from '@/common/blobType'
import moment from 'moment'
import {
    partyHysaveHyjl,
    partyHydeleteHyjl,
} from './service/index'
import handleaddEdit from './handleaddEdit.vue'
import recordPrint from './recordPrint.vue'
import recordPrintTable from './recordPrintTable.vue'
export default {
    components:{
        commpVxeTable,
        handleaddEdit,
        recordPrint,
        recordPrintTable,
    },
    props:{
        fzllx:{
            type: String,
            default: '',
            required: false
        }
    },
    data(){
        return{
            formItem:[{
                label: '会议标题',
                model: 'fhybt',
            },{
                label: '会议地点',
                model: 'fhydd',
            },{
                label: '记录人员',
                model: 'fhyjlryxm',
            },{
                label: '会议状态',
                model: 'fhyzt',
                options:[{value:'未开始',label:'未开始'},{value:'已完成',label:'已完成'}],
                type:'Select'
            },{
                label: '开始时间',
                model: 'startTime',
                format:'YYYY-MM-DD',
                type:'datePicker'
            },{
                label: '结束时间',
                model: 'endTime',
                format:'YYYY-MM-DD',
                type:'datePicker'
            }],
            columnsVxe:[
            { 
                type: 'checkbox', 
                width: 60 ,
                fixed: 'left'
            },{
                title: '会议标题', //列头显示文字
                field: 'fhybt',
            },{
                title: '会议地点', //列头显示文字
                field: 'fhydd',
                align:'left',
            },{
                title: '会议时间',
                field: 'fhysj',
            },{
                title: '会议摘要',
                field: 'fhyzy',
            },{
                title: '记录人员',
                field: 'fhyjlryxm',
            },{
                title: '会议状态',
                field: 'fhyzt',
                slots: {
                    // 使用插槽模板渲染
                    default: 'fhyzt_name',
                },
                width:90,
            },{
                title: '操作',
                field: 'id',
                slots: {
                    // 使用插槽模板渲染
                    default: 'operation_btn',
                },
                fixed: 'right',
                width:200
            }],
            dataTableConfig:{
                api: assessCheckApi.partyHyqueryMyHyjlPageList,
                rowId: 'id',
                paramet:{
                }
            },
            addEditParameter:{},
            methodList:[{
                name:'',
                editName:partyHysaveHyjl,
                deleteName:partyHydeleteHyjl,
                addName:partyHysaveHyjl,
            }],
            refreshTable:null,
            checkboxIdArr:[],
            
        }
    },
    watch:{

    },
    mounted(){
        
    },
    methods:{
        checkboxChange(val){
            //console.log(val)
            val.forEach(item => {
                this.checkboxIdArr.push(item.id)
            });
        },
        printBatchDetailsClick(){
            if(this.checkboxIdArr.length){
                this.$refs.recordPrintRef.getData({ids:this.checkboxIdArr.join(',')})
                this.$refs.recordPrintRef.visible = true
            }else{
                this.$message.warning('请选择打印项')
            }
        },
        printAllTableClick(val){
            let data = {}
            if(val){
                data = val
            }else{
                if(this.checkboxIdArr.length){
                    data = {ids:this.checkboxIdArr.join(',')}
                }else{
                    this.$message.warning('请选择打印项')
                    return false
                }
            }
            this.$refs.recordPrintTableRef.getData(data)
            this.$refs.recordPrintTableRef.visible = true
        },
        printDetailsClick(val){
            this.$refs.recordPrintRef.getData({ids:val.id})
            this.$refs.recordPrintRef.visible = true
        },
        handleClick(val){
            let refName = 'addEditRef0'
            this.$refs[refName].getData({...val,index:0,view:true})
            this.$refs[refName].visible = true
        },
        addClick(index){
            let refName = 'addEditRef'+index
            this.$refs[refName].getData({index:index,fzllx:this.fzllx})
            this.$refs[refName].visible = true
        },
        editClick(val,index,view){
            let refName = 'addEditRef'+index
            this.$refs[refName].getData({...val,fzllx:this.fzllx,index:index,view:view?true:false})
            this.$refs[refName].visible = true
        },
        addItem(val,vis,isTip){
            //console.log('新增',val)
            let refName = 'addEditRef'+val.index
            this.methodList[val.index].addName(val).then(res=>{
                if(res.code == 200){
                    this.refreshTable = Date.now()
                    if(!isTip){
                        this.$message.success(res.message)
                    }
                    
                    this.$refs[refName].getData({...val,id:res.result.id})
                    this.$refs[refName].visible = vis
                    //console.log(res)
                }else{
                    this.$message.warning(res.message)
                }
            })
        },
        editItem(val,vis){
            //console.log('编辑',val)
            let refName = 'addEditRef'+val.index
            this.methodList[val.index].editName(val).then(res=>{
                if(res.code == 200){
                    this.refreshTable = Date.now()
                    this.$message.success(res.message)
                    this.$refs[refName].visible = vis
                }else{
                    this.$message.warning(res.message)
                }
            })
        },
        deleteClick(val,index){
            var that = this
            this.$confirm({
                title:'您确认要删除吗？',
                // icon: createVNode(ExclamationCircleOutlined),
                onOk() {
                    that.methodList[index].deleteName({id:val.id}).then(res=>{
                        if(res.code == 200){
                            that.$message.success('删除成功')
                            that.refreshTable = Date.now()
                        }else{
                            that.$message.warning(res.message)
                        }
                    })
                },
                
            });
        },
    }
}
</script>
<style lang="less">
.waiting-queue-box{
    background: #fff;
    .waiting-content-v{
        height: calc(100vh - 191px -48px);
    }
}
</style>